package util
{
	import mx.formatters.DateFormatter;
	
	public class DateConverter
	{
		private static var formatter:DateFormatter = new DateFormatter();
		private static var datePattern:RegExp = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
		formatter.formatString = "YYYY-MM-DD";
		
		public static function parseDateString(dateString:String):Date {
			var result:Array = datePattern.exec(dateString);
			
			if (result == null) return null;
			
			var year:int = parseInt(result[1]);
			var month:int = parseInt(result[2]);
			var day:int = parseInt(result[3]);
			
			return new Date(year, month - 1, day);
		}
		
		public static function formatDate(dateToFormat:Date):String {
			return formatter.format(dateToFormat);
		}
	}
}